package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.PmsProductAttributeCategory;
import com.itheima.mapper.PmsProductAttributeCategoryMapper;
import com.itheima.service.db.PmsProductAttributeCategoryService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
    @Autowired
    private PmsProductAttributeCategoryMapper ppacMapper;

    @Override
    public List<PmsProductAttributeCategory> findAll() {
        return ppacMapper.selectList(null);
    }

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize) {
        Page<PmsProductAttributeCategory> page = new Page<>(pageNum, pageSize);
        Page<PmsProductAttributeCategory> attributePage = ppacMapper.selectPage(page, null);
        return new PageBeanVo(pageNum, pageSize, attributePage.getTotal(), attributePage.getRecords());
    }

    @Override
    public void save(PmsProductAttributeCategory ppac) {
        ppacMapper.insert(ppac);
    }

    @Override
    public void update(Long id, String name) {
        ppacMapper.updateName(id, name);
    }

    @Override
    public PmsProductAttributeCategory findById(Long id) {
        return ppacMapper.selectById(id);
    }

    @Override
    public void add(Integer type, Long id) {
        if (type == 0) {
            ppacMapper.addAttribute(id);
        } else {
            ppacMapper.addParam(id);
        }
    }

    @Override
    public void subtract(Integer type, Long id, int length) {
        if (type == 0) {
            ppacMapper.subAttribute(id, length);
        } else {
            ppacMapper.subParam(id, length);
        }
    }

    @Override
    public void delete(Long id) {
        ppacMapper.deleteById(id);
    }
}
